Use case: Starting a write/read in polling indirect mode

Starting a write/read operation in polling indirect mode.

Sequence diagram

Starting a write/read operation in polling indirect mode

  @startuml

    == Initialization and configuration ==

    == Process polling mode ==
    "Application" -> "OSPI" : HAL_OSPI_Command()/HAL_OSPI_HyperbusCmd()
    note right: Enable write operation
    "OSPI" --> "Application" : HAL_OK or HAL_ERROR

    "Application" -> "OSPI" : HAL_OSPI_AutoPolling()
    note right: Reconfigure OSPI to automatic polling mode to wait for write enabling
    "OSPI" --> "Application" : match completed

    group opt
    "Application" -> "OSPI" : HAL_OSPI_SetFifoThreshold()
    note right: Configure the fifo threshold
    end group

    "Application" -> "OSPI" : HAL_OSPI_Command()/HAL_OSPI_HyperbusCmd()
    "OSPI" --> "Application" : HAL_OK or HAL_ERROR

    "Application" -> "OSPI" : HAL_OSPI_Transmit()
    "OSPI" --> "Application" :

    "Application" -> "OSPI" : HAL_OSPI_Command()/HAL_OSPI_HyperbusCmd()
    "OSPI" --> "Application" : HAL_OK or HAL_ERROR

    "Application" -> "OSPI" : HAL_OSPI_AutoPolling()
    note right: Reconfigure OSPI to automatic polling mode to wait end of operation
    "OSPI" --> "Application" : match completed

    "Application" -> "OSPI" : HAL_OSPI_Command()/HAL_OSPI_HyperbusCmd()
    "OSPI" --> "Application" : HAL_OK or HAL_ERROR

    "Application" -> "OSPI" : HAL_OSPI_Receive()
    "OSPI" --> "Application" :

    @enduml

Code snippet

HAL1

HAL2

/* Perform the init and configuration as per the first use case*/

OSPI_HandleTypeDef ospi;

OSPI_RegularCmdTypeDef sCommand={0};
scommand.OperationType      = HAL_OSPI_OPTYPE_COMMON_CFG;
scommand.InstructionMode    = HAL_OSPI_INSTRUCTION_8_LINES;
scommand.InstructionWidth   = HAL_OSPI_INSTRUCTION_8_BITS;
scommand.InstructionDTRMode = HAL_OSPI_INSTRUCTION_DTR_DISABLE;
scommand.Instruction        = WRITE_REG_CMD;
scommand.AddressMode        = HAL_OSPI_ADDRESS_8_LINES;
scommand.AddressWidth       = HAL_OSPI_ADDRESS_32_BITS;
scommand.AddressDTRMode     = HAL_OSPI_ADDRESS_DTR_ENABLE;
scommand.Address            = Address;
scommand.AlternateBytesMode = HAL_OSPI_ALT_BYTES_NONE;
scommand.DataMode           = HAL_OSPI_DATA_8_LINES;
scommand.DataDTRMode        = HAL_OSPI_DATA_DTR_ENABLE;
scommand.DataLength         = 2;
scommand.DummyCycles        = 0;
scommand.DQSMode            = HAL_OSPI_DQS_DISABLE;



HAL_OSPI_Command(&ospi, &scommand, OSPI_TIMEOUT);

HAL_OSPI_AutoPolling(&ospi, &sConfig, OSPI_TIMEOUT);

HAL_OSPI_SetFifoThreshold(&ospi, 4);

HAL_OSPI_Command(&ospi, &scommand, OSPI_TIMEOUT);

HAL_OSPI_Transmit(&ospi, &reg, OSPI_TIMEOUT);

HAL_OSPI_Command(&ospi, &sCommand, OSPI_TIMEOUT);

HAL_OSPI_AutoPolling(&ospi, &sConfig, OSPI_TIMEOUT);

HAL_OSPI_Command(&ospi, &sCommand, OSPI_TIMEOUT);

HAL_OSPI_Receive(&ospi, (uint8_t *)aRxBuffer, OSPI_TIMEOUT);
/* Perform the init and configuration as per the first use case*/

hal_xspi_handle_t xspi;

command.operation_type = HAL_XSPI_OPERATION_COMMON_CFG;
command.io_select = HAL_XSPI_IO_7_0;
command.alternate_bytes = 0U;
command.alternate_bytes_width = HAL_XSPI_ALTERNATE_BYTES_8BIT;
command.alternate_bytes_mode = HAL_XSPI_ALTERNATE_BYTES_NONE;
command.alternate_bytes_dtr_mode_status = HAL_XSPI_ALTERNATE_BYTES_DTR_DISABLED;
/* Specific parameters for the Sector Erase command */
command.instruction = WRITE_REG_CMD;
command.instruction_mode = HAL_XSPI_INSTRUCTION_8LINES;
command.instruction_width = HAL_XSPI_INSTRUCTION_32BIT;
command.instruction_dtr_mode_status = HAL_XSPI_INSTRUCTION_DTR_DISABLED;
command.addr = MX25_FIRST_BLOCK_ADDR;
command.addr_mode = HAL_XSPI_ADDR_8LINES;
command.addr_width = HAL_XSPI_ADDR_32BIT;
command.addr_dtr_mode_status = HAL_XSPI_ADDR_DTR_ENABLED;
command.data_mode = HAL_XSPI_REGULAR_DATA_NONE;
command.data_dtr_mode_status = HAL_XSPI_DATA_DTR_ENABLED;
command.dummy_cycle = 0;
command.dqs_mode_status = HAL_XSPI_DQS_DISABLED;
command.size_byte = 2U;
HAL_XSPI_SendRegularCmd(&xspi, &command, XSPI_TIMEOUT);

HAL_XSPI_ExecRegularAutoPoll(&xspi, &pPollingModeCfg, XSPI_TIMEOUT);

HAL_XSPI_SetFifoThreshold(&xspi, 4);

HAL_XSPI_SendRegularCmd(&xspi, &command, XSPI_TIMEOUT);

HAL_XSPI_Transmit(&xspi, p_data, XSPI_TIMEOUT);

HAL_XSPI_SendRegularCmd(&xspi, &command, XSPI_TIMEOUT);

HAL_XSPI_ExecRegularAutoPoll(&xspi, &pPollingModeCfg, XSPI_TIMEOUT);

HAL_XSPI_SendRegularCmd(&xspi, &command, XSPI_TIMEOUT);

HAL_XSPI_Receive(&xspi, (uint8_t *)aRxBuffer, XSPI_TIMEOUT);

Key changes

  1. In HAL2, OSPI APIs are replaced by XSPI APIs (for example, HAL_OSPI_Command() becomes HAL_XSPI_SendRegularCmd()).

  2. In HAL2, the polling sequence uses HAL_XSPI_ExecRegularAutoPoll() for automatic polling.